package org.jfk.tomcatbell;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TomcatBell extends Thread{
	private String stop_cmd;
	private String start_cmd;

	public TomcatBell(String stop_cmd,String start_cmd){
		this.start_cmd = start_cmd;
		this.stop_cmd = stop_cmd;
	}
	
	@Override
	public void run() {
        try{        
            //关闭tomcat服务      
            System.out.println("stop : "+stop_cmd);
            Process p1 = Runtime.getRuntime().exec(stop_cmd);  
            BufferedReader in1 = new BufferedReader(new InputStreamReader(p1.getInputStream()));
            String str;
            while((str=in1.readLine())!=null){
            	System.out.println(str);
            }
            
            Thread.sleep(5000);  

            //启动tomcat服务  
            System.out.println("start : "+start_cmd);

            Process p2=Runtime.getRuntime().exec(start_cmd);
            BufferedReader in2 = new BufferedReader(new InputStreamReader(p2.getInputStream()));
            while((str=in2.readLine())!=null){
            	System.out.println(str);
            }
        }catch(Exception e){  
            e.printStackTrace();  
        }
	}
	
}
